package com.pdf.pdfserver.controller;

import com.pdf.pdfserver.service.solr.ArticleSolrService;
import com.pdf.pdfserver.vo.ArticleVO;
import com.pdf.pdfserver.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

/**
 * @Author songfz
 * @Description 全文搜索demo
 * @Date 2022/1/10
 */
@RestController
@RequestMapping("api/solr")
public class SolrController {

    @Autowired
    private ArticleSolrService solrService;


    @PostMapping("save")
    public void save(@RequestBody ArticleVO articleVO){

        solrService.addArticle(articleVO);
    }

    @RequestMapping("search")
    public PageVO<ArticleVO> search(@RequestParam(value = "q",required = false) String key,
                                    @PageableDefault(page = 1,size =20 ) Pageable pageable){

        return solrService.searchArticle(key,pageable);
    }

    @DeleteMapping("delete/title/{title}")
    public void delete(@PathVariable("title") String title){

        solrService.deleteByTitle(title);
    }

    @DeleteMapping("delete/id/{id}")
    public void deleteById(@PathVariable("id") String id){

        solrService.deleteById(id);
    }

    @PutMapping("update")
    public void update(@RequestBody ArticleVO articleVO) {

        solrService.updateArticle(articleVO);
    }
}
